package com.jiang.gzjp.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/** 
 * MyEclipse Struts
 * Creation date: 02-27-2019
 * 
 * XDoclet definition:
 * @struts.form name="loginForm"
 */
public class LoginForm extends ActionForm {

	private static final long serialVersionUID = 8690239290980814004L;

	/** password property
	 *  自动产生getter/setter
	 */
	private String password;

	/** username property
	 * 自动产生getter/setter
	 *  */
	private String username;

	/** 
	 * Method validate
	 * @param mapping
	 * @param request
	 * @return ActionErrors
	 */
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		// mapping 是配置跳转路由相关的对象
		// 走到这里validate, 说明已经参数赋值了
		ActionErrors actionErrors = new ActionErrors();
		// 这里可以使用request.getParameter()获取参数，但是框架已经自动封装好了，直接从属性中获取
		if(StringUtils.isBlank(username)){
			// 第一个表示提交参数的名称，第二个表示错误信息
			actionErrors.add("username", new ActionMessage("validate.msg.null.username"));
		}
		if(StringUtils.isBlank(password)){
			actionErrors.add("password", new ActionMessage("validate.msg.null.password"));
		}
		// 如果验证不通过会自动去寻找struts-config.xml中的action中配置的input属性地址
		return actionErrors;
	}

	/** 
	 * Method reset 这里用作加载JSP前的初始化 与前端JSP中的传参是双向绑定的
	 * @param mapping
	 * @param request
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		
		this.username = "hahaha";
		this.password="ssss";
		
	}

	/** 
	 * Returns the password.
	 * @return String
	 */
	public String getPassword() {
		return password;
	}

	/** 
	 * Set the password.
	 * @param password The password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/** 
	 * Returns the username.
	 * @return String
	 */
	public String getUsername() {
		return username;
	}

	/** 
	 * Set the username.
	 * @param username The username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}
}